import wave
import os
import utils




ver = 'v2'
def wav_48k():
    wavs_dir = f'../resource/{ver}/noise'
    wavs_48k_dir = f'../resource/{ver}/noise_48k'
    utils.resample_wavs(wavs_dir,wavs_48k_dir);


    wavs_dir = f'../resource/{ver}/speech'
    wavs_48k_dir = f'../resource/{ver}/speech_48k'
    utils.resample_wavs(wavs_dir,wavs_48k_dir);

def merge_wav():

    wavs_dir = f'../resource/{ver}/noise_48k'
    output_file = f'../resource/{ver}/noise_merged.wav'
    if os.path.exists(output_file):
        os.remove(output_file)
    utils.merge_wavs(wavs_dir, output_file)


    wavs_dir = f'../resource/{ver}/speech_48k'
    output_file = f'../resource/{ver}/speech_merged.wav'
    if os.path.exists(output_file):
        os.remove(output_file)
    utils.merge_wavs(wavs_dir, output_file)

def wav_2_pcm():
    noise_wav = f'../resource/{ver}/noise_merged.wav'
    noise_pcm = f'../resource/{ver}/background_noise.pcm'
    utils.wav_to_pcm(noise_wav, noise_pcm)

    speech_wav = f'../resource/{ver}/speech_merged.wav'
    speech_pcm = f'../resource/{ver}/speech.pcm'
    utils.wav_to_pcm(speech_wav, speech_pcm)


wav_48k()
merge_wav()
wav_2_pcm()